package com.moju.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();

        session.setAttribute("user","admin");

//        session.invalidate();

        session.setMaxInactiveInterval(5);
        //session 失效的方式:
        /**
         * 1. 关闭浏览器     ， 下次找不到上次那个sessionId了
         *
         *
         * 2. session.invalidate();
         *
         *
         *
         * 3.session.setMaxInactiveInterval(60); 过了 session的存活时间
         *  以秒为单位。负数时间指示会话永远不会超时。
         *
         *
         * 4.    <session-config>
         *           <session-timeout>60</session-timeout>
         *       </session-config>
         */



        request.getRequestDispatcher("/login.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
